package text_2023_09_21;

/**
 * @author Vv
 * @version 1.0
 * @project coding_learn
 * @description
 * @date 2023/9/21 17:20:37
 */
class StringExercise{
    public static void checkEmail(String emaill) throws EmailCheckException{
        int len = emaill.length();
        int begin = emaill.indexOf('@');
        int end = emaill.lastIndexOf('@');
        int dot = emaill.indexOf('.',begin);
        if(emaill.length() > 20){
            throw new EmailCheckException("Email长度不能大于20");
        }else if(begin != end){
            throw new EmailCheckException("Email中含有多个@");
        }else if(begin == -1 || begin == 0 || begin == (len - 1)){
            throw new EmailCheckException("Email 中 没有@位置错误");
        }else if(dot == -1){
            throw new EmailCheckException("@后缺少域分隔符");
        }else if(dot == (len - 1)){
            throw new EmailCheckException("分隔符错误");
        }
    }
}
public class EmailCheckException extends Exception{
    public EmailCheckException(String message){
        super(message);

    }
}
